//
//  DisSecondTableViewCell.m
//  LT
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DisSecondTableViewCell.h"
#import "DisSecCollectionViewCell.h"

static NSString *const disSecondCell = @"disSecondCell";

@interface DisSecondTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

//将collectionView做成属性
@property(nonatomic,strong)UICollectionView *disCollectionView;


@end

@implementation DisSecondTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;
    
}

-(void)createCollectionView{
    
    self.dataArray = [NSMutableArray array];
    
    //建立Collection的布局
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //这里改红色坐标
    flowLayout.itemSize = CGSizeMake(200 * WIDTHCELL, 190 * WIDTHCELL);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.disCollectionView = [[UICollectionView alloc]initWithFrame:[[UIScreen mainScreen]bounds] collectionViewLayout:flowLayout];
     self.disCollectionView.backgroundColor = [UIColor clearColor];
    self.disCollectionView.delegate = self;
    self.disCollectionView.dataSource = self;
    
    [self.disCollectionView registerClass:[DisSecCollectionViewCell class] forCellWithReuseIdentifier:@"disSecondCell"];
        [self.contentView addSubview:self.disCollectionView];

    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.disCollectionView.frame = CGRectMake(5* WIDTHCELL, 5* WIDTHCELL, (self.contentView.frame.size.width - 10), (self.contentView.frame.size.height - 10));


}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DisSecCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"disSecondCell"forIndexPath:indexPath];
   // cell.backgroundColor = [UIColor redColor];
   cell.discount = self.dataArray[indexPath.row];
    
    return cell;
    
}

//cell数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
}






//数组传值
-(void)setAllArray:(NSMutableArray *)allArray{
    _allArray = allArray;
    self.dataArray = [NSMutableArray arrayWithArray:_allArray];
    [self.disCollectionView reloadData];


}

//cell的点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.discountBlock(indexPath.row );
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
